"""
2.语法
    Keys类
    元素.send_keys(Keys.键名称)
"""

# 1.导入需要的包
from time import sleep
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

# 2. 创建浏览器驱动, 并打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://www.baidu.com")

# 3. 元素定位+元素操作
sleep(3)
search = driver.find_element(By.ID, "kw")
search.send_keys("selenium4")
sleep(3)
search.send_keys(Keys.BACKSPACE)  # 键入退格键
sleep(3)
search.send_keys(Keys.ENTER)  # 键入回车键

# 4. 关闭浏览器
sleep(3)
driver.quit()
